/**
 * 培养异动
 */
import fetch from 'common/src/utils/fetch';

/**
 * 博转硕权限管理列表
 * @param {*} data
 */
export function getPermissionList(data) {
  return fetch({
    url: '/api/studentservice/docToMaster/getPermissionList',
    data: data,
    method: 'post'
  });
}
/**
 * 新增博转硕权限
 * @param {*} data
 */
export function addPermission(data) {
  return fetch({
    url: '/api/studentservice/docToMaster/addPermission',
    data: data,
    method: 'post'
  });
}
/**
 * 编辑博转硕权限
 * @param {*} data
 */
export function updatePermission(data) {
  return fetch({
    url: '/api/studentservice/docToMaster/updatePermission',
    data: data,
    method: 'post'
  });
}
/**
 * 删除博转硕权限
 * @param {*} id
 */
export function deletePermission(id) {
  return fetch({
    url: '/api/studentservice/docToMaster/deletePermission?id=' + id,
    method: 'get'
  });
}
/**
 * 代学生申请列表
 * @param {*} data
 */
export function getRepStuAppList(data) {
  return fetch({
    url: '/api/studentservice/docToMaster/getRepStuAppList',
    data: data,
    method: 'post'
  });
}
/**
 * 根据硕士年级与硕士入学季节关联硕士阶段开始时间与硕士阶段结束时间
 * @param {*} data
 */
export function getMasTime(data) {
  return fetch({
    url: '/api/studentservice/docToMaster/getMasTime',
    data: data,
    method: 'post'
  });
}
/**
 * 获取学生硕士导师列表
 */
export function getStuTeas() {
  return fetch({
    url: '/api/studentservice/docToMaster/getStuTeas'
  });
}
/**
 * 获取学生硕士导师（全部）列表
 */
export function findTeacherList(data) {
  return fetch({
    url: '/api/studentservice/docToMaster/findTeacherList',
    method: 'post',
    data
  });
}
/**
 * (学生、学院教务员、学校管理员)申请时弹出部分学生信息
 */
export function getStudentInfo(studentId) {
  return fetch({
    url: '/api/studentservice/docToMaster/getStudentInfo?studentId=' + studentId
  });
}
/**
 * (学生、学院教务员、学校管理员)提交博转硕申请
 * @param {*} data
 */
export function submitManage(data) {
  return fetch({
    url: '/api/studentservice/docToMaster/submitManage',
    data: data,
    method: 'post'
  });
}
/**
 *(学院教务员、学校管理员)批量提交博转硕申请
 * @param {*} data
 */
export function batchSubmitManage(data) {
  return fetch({
    url: '/api/studentservice/docToMaster/batchSubmitManage',
    data: data,
    method: 'post'
  });
}
/**
 *博转硕管理列表
 * @param {*} data
 */
export function getmanageList(data) {
  return fetch({
    url: '/api/studentservice/docToMaster/getmanageList',
    data: data,
    method: 'post'
  });
}
/**
 *新增、编辑博转硕申请(学生使用)
 * @param {*} data
 */
export function addmanage(data) {
  return fetch({
    url: '/api/studentservice/docToMaster/addmanage',
    data: data,
    method: 'post'
  });
}
/**
 * 删除博转硕申请
 * @param {*} id
 */
export function deleteManage(id) {
  return fetch({
    url: '/api/studentservice/docToMaster/deleteManage?id=' + id
  });
}
/**
 * 单个博转硕审批进度
 * @param {*} workflowNo
 */
export function approvalHistory(workflowNo, submissionType) {
  return fetch({
    url: '/api/studentservice/docToMaster/approvalHistory?workflowNo=' + workflowNo + '&submissionType=' + submissionType
  });
}
/**
 * 导出博转硕申请表
 */
export function exportDocToMasterDocxZip(data) {
  let params = '?';
  Object.keys(data).forEach(key => {
    if (data[key] !== null && data[key] != '' && data[key] !== undefined) {
      params += key + '=' + data[key] + '&&';
    }
  });
  return (
    '/api/studentservice/docToMaster/exportDocToMasterDocxZip' +
    encodeURI(params)
  );
}
/**
 * 导出博转硕管理列表
 */
export function exportManageList(data) {
  let params = '?';
  Object.keys(data).forEach(key => {
    if (data[key] !== null && data[key] != '' && data[key] !== undefined) {
      params += key + '=' + data[key] + '&&';
    }
  });
  return '/api/studentservice/docToMaster/exportManageList' + encodeURI(params);
}


function downloadFile(data, url, fileName) {
  fetch({
    url: url,
    method: 'POST',
    data,
    responseType: 'blob'
  }).then(resp => {
    if (!resp) {
      return;
    }
    let url = window.URL.createObjectURL(new Blob([resp]));
    let link = document.createElement('a');
    link.style.display = 'none';
    link.href = url;
    link.setAttribute('download', fileName);
    document.body.appendChild(link);
    link.click();
  });
}

/**
 * 获取转导师 学生信息
 * @author yidonge
 */
export function getStudentInfoToTutor(data) {
  return fetch({
    url: '/api/studentservice/stuChangeTutor/getChangeTutorList',
    data: data,
    method: 'post'
  });
}

/**
 * (学生、学院教务员、学校管理员)提交转导师申请
 * @author yidonge
 * @param {*} data
 */
export function submitManageTotutor(data) {
  return fetch({
    url: '/api/studentservice/stuChangeTutor/submitRequest',
    data: data,
    method: 'post'
  });
}

/**
 *转导师管理列表
 * @author yidonge
 * @param {*} data
 */
export function getListInfoToTutor(data) {
  return fetch({
    url: '/api/studentservice/stuChangeTutor/manageChangeTutorList',
    data: data,
    method: 'post'
  });
}

/**
 * 学生新增提交申请转导师 （草稿状态）
 * @author yidonge
 * @param {*} data
 */
export function createApplyInfoByStudent(data) {
  return fetch({
    url: '/api/studentservice/stuChangeTutor/addChangeTutorDraft',
    data: data,
    method: 'put'
  });
}

/**
 * 学生修改提交申请转导师（草稿状态）
 * @author yidonge
 * @param {*} data
 */
export function editApplyInfoByStudent(data) {
  return fetch({
    url: '/api/studentservice/stuChangeTutor/editChangeTutorDraft',
    data: data,
    method: 'put'
  });
}
/**
 * 撤回（只能撤回导师未审批的）
 * @author yidonge
 * @param {*} data
 */
 export function cancelRequest(data) {
  return fetch({
    url: '/api/studentservice/stuChangeTutor/cancelRequest',
    data: data,
    method: 'post'
  });
}
/**
 * 删除转导师（只能删除草稿状态）
 * @author yidonge
 * @param {*} data
 */
export function deleteManageToTutor(data) {
  return fetch({
    url: '/api/studentservice/stuChangeTutor/deleteStuChangeTutorInfo',
    data: data,
    method: 'delete'
  });
}

/**
 *导出转导师列表
 * @author yidonge 2019-11-28
 */
export function exprotListInfoToTutor(data) {
  let url =
    '/api/studentservice/stuChangeTutor/exportChangeTutorExcel';
  downloadFile(data, url, 'exportChangeTutorExcel.xlsx');
}
/**
 * 获取单个转导师审批进度
 * @author yidonge 2019-11-28
 * @param {*} workflowNo
 */
export function getChangeTutorHistory(workflowNo) {
  return fetch({
    url: '/api/studentservice/stuChangeTutor/getChangeTutorHistory?workflowNo=' + workflowNo
  });
}
/**
 *(学院教务员、学校管理员)批量提交博转硕申请
 @author yidonge
 * @param {*} data
 */
export function batchSubmitManageToTutor(data) {
  return fetch({
    url: '/api/studentservice/stuChangeTutor/batchSubmitRequest',
    data: data,
    method: 'post'
  });
}

/**
 *新增、编辑博转硕申请(学生使用)
 * @param {*} data
 */
export function reviewerUpdateManage(data) {
  return fetch({
    url: '/api/studentservice/docToMaster/reviewerUpdateManage',
    data: data,
    method: 'post'
  });
}

/**
 *【删除】【提前/延期】答辩草稿状态下的学生申请记录
 * @param {*} data
 */
export function deleteOralDefenseInfo(data) {
  return fetch({
    url: '/api/studentservice/oralDefense/deleteOralDefenseInfo',
    data: data,
    method: 'delete'
  });
}
/**
 *【编辑/新增】【保存】【提前/延迟答辩】申请记录
 * @param {*} data
 */
export function editOralDefense(data) {
  return fetch({
    url: '/api/studentservice/oralDefense/editOralDefense',
    data: data,
    method: 'post'
  });
}
/**
 *新增提前答辩申请
 * @param {*} data
 */
export function applyAdvancedOralDefense(data) {
  return fetch({
    url: '/api/studentservice/oralDefense/applyAdvancedOralDefense',
    data: data,
    method: 'post'
  });
}
/**
 *新增延迟答辩申请
 * @param {*} data
 */
export function applyDelayedOralDefense(data) {
  return fetch({
    url: '/api/studentservice/oralDefense/applyDelayedOralDefense',
    data: data,
    method: 'post'
  });
}
/**
 *【导出】【提前/延期】答辩申请记录
 * @param {*} data
 */
export function exportOralDefenseInfo(data) {
  let params = '?';
  Object.keys(data).forEach(key => {
    if (data[key] !== null && data[key] !== '' && data[key] !== undefined) {
      params += key + '=' + data[key] + '&&';
    }
  });
  return '/api/studentservice/oralDefense/exportOralDefenseInfo' + encodeURI(params);
}
/**
 *根据学生ID查询学生信息
 * @param {*} studentId
 */
export function selectStudentInfoByStuId(studentId) {
  return fetch({
    url: '/api/studentservice/oralDefense/selectStudentInfoByStuId?studentId=' + studentId
  });
}
/**
 *获取审批进度详情
 @param {*} workflowNo 工作流no
 @param {*} module_ 提前答辩2   延期答辩3
 */
export function oralApprovalHistory(workflowNo, module_) {
  return fetch({
    url: '/api/studentservice/oralDefense/approvalHistory?workflowNo=' + workflowNo + '&module=' + module_
  });
}
/**
 *获取超期名单
 * @param {*} data
 */
export function selectOverdueList(data) {
  return fetch({
    url: '/api/studentservice/oralDefense/selectOverdueList',
    data: data,
    method: 'post'
  });
}
/**
 *【导出】超期学生名单
 * @param {*} data
 */
export function exportOverdueList(data) {
  let params = '?';
  Object.keys(data).forEach(key => {
    if (data[key] !== null && data[key] != '' && data[key] !== undefined) {
      params += key + '=' + data[key] + '&&';
    }
  });
  return '/api/studentservice/oralDefense/exportOverdueList' + encodeURI(params);
}

/**
 * 【获取】已申请【提前/延期】答辩的学生名单记录
 * @param studentDefense
 * @return
 */
export function selectOralDefense(data) {
  return fetch({
    url: '/api/studentservice/oralDefense/selectOralDefense',
    data: data,
    method: 'post'
  });
}
/**
 * 审批过程中修改提前答辩时间
 * @param {*studentDefense} data
 */
export function updateDefenseTime(data) {
  return fetch({
    url: '/api/studentservice/oralDefense/updateDefenseTime',
    data: data,
    method: 'put'
  });
}
/**
 * 根据条件，查询研究生专业列表
 * @param {*} data
 */
export function getGraduateDegreeByColleges(data) {
  return fetch({
    url: '/api/baseresservice/graduateDegree/getGraduateDegreeByColleges',
    data: data,
    method: 'post'
  });
}
/**
 * 是否超过最长学习年限
 * @param {*} data
 */
export function isExceedLimit(data) {
  return fetch({
    url: '/api/studentservice/oralDefense/isExceedLimit',
    data: data,
    method: 'post'
  });
}
/**
 * 获取学期结束时间
 * @param {*} studentId
 * @param {*} lengthSchooling
 */
export function getLastTermDate(studentId, lengthSchooling) {
  return fetch({
    url: '/api/studentservice/oralDefense/getLastTermDate?studentId=' + studentId + "&lengthSchooling=" + lengthSchooling
  });
}

// 文件从obs转换到预览服务过程1：将文件转为字节数组
export function fileToByteArray(data) {
  return fetch({
    url: `/api/studentservice/stuChangeTutor/fileToByteArray?fileJson=` + JSON.stringify(data),
    method: 'get',
    data
  });
}